﻿
@using DCMS.Web.Extensions;
@using DCMS.Web.Framework.UI;
@using DCMS.ViewModel.Models.Users;

@model UserRoleListModel


<section id="content_wrapper">

    <!-- Start: Topbar-Dropdown -->
    <div id="topbar-dropmenu">
        @await Html.PartialAsync("_ToolBox")
    </div>
    <!-- End: Topbar-Dropdown -->
    <!-- Start: Topbar -->
    <header id="topbar">
        <div class="topbar-left">
            <ol class="breadcrumb">
                <li class="crumb-active">
                    <a href="#">档案</a>
                </li>
                <li class="crumb-icon">
                    <a href="@Url.RouteUrl("HomePage")">
                        <span class="glyphicon glyphicon-home"></span>
                    </a>
                </li>
                <li class="crumb-link">
                    <a href="#">员工相关</a>
                </li>
                <li class="crumb-trail">操作员角色</li>
            </ol>
        </div>
        <div class="topbar-right">
            <div class="ml15 ib va-m" id="toggle_sidemenu_r">
                <a href="#" class="pl5">
                    <i class="fa fa-sign-in fs22 text-primary"></i>
                    <span class="badge badge-hero badge-danger">3</span>
                </a>
            </div>
        </div>
    </header>
    <!-- End: Topbar -->
    <!-- Begin: Content -->
    <section id="content" class="formSection">

        <div class="special-alerts">
            <div class="alert alert-danger light alert-dismissable" id="alert-demo-2" style="display: none;">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                <i class="fa fa-info pr10"></i>
                <strong>您没有被授权此操作!</strong>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">

                <form asp-action="List" asp-controller="UserRole" method="get" id="formSearch" novalidate="novalidate">
                    <div class="panel panel-default" id="panel0">
                        <div class="panel-heading">
                            <span class="glyphicon glyphicon-search"></span> 高级搜索
                            <a class="btn btn-default btn-sm pull-right m5 mrn p5 pbn" id="AdvancedSearch"><i class="fa fa-angle-double-right"></i></a>
                        </div>
                        <div class="panel-body p10">
                            <div class="row">
                                <div class="col-sm-2">
                                    <input asp-for="Name" class="form-control" placeholder="角色关键字..." />
                                </div>
                                <div class="col-sm-10">
                                    <button id="btn_query" type="submit" class="btn btn-primary btn-block">
                                        <span class="glyphicon glyphicon-search mr5" aria-hidden="true"></span>查询
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>



                <div class="panel">
                    <div class="panel-heading">
                        <div class="panel-title">
                            <span class="glyphicon glyphicon-tasks"></span> 角色列表
                        </div>
                    </div>
                    <div class="panel-body p10">


                        <div class="bootstrap-table">
                            <div class="fixed-table-toolbar">
                                <div class="bs-bars pull-left">
                                    <div id="toolbar" class="btn-group">
                                        <button id="btn_add" type="button" class="btn btn-primary btn-sm">
                                            <span class="glyphicon glyphicon-plus mr5" aria-hidden="true"></span>添加
                                        </button>
                                        @*<button id="btn_edit" type="button" class="btn btn-info">
                        <span class="glyphicon glyphicon-pencil mr5" aria-hidden="true"></span>编辑
                    </button>
                    <button id="btn_delete" type="button" class="btn btn-danger">
                        <span class="glyphicon glyphicon-remove mr5" aria-hidden="true"></span>删除
                    </button>*@
                                    </div>
                                </div>
                                <div class="columns columns-right btn-group pull-right">
                                    <button class="btn btn-default" type="button" id="btn_refresh" name="refresh" aria-label="refresh" title="刷新"><i class="glyphicon glyphicon-refresh icon-refresh"></i></button>
                                </div>
                            </div>
                            <div class="fixed-table-container">
                                <div class="fixed-table-body">


                                    <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                @*<th class="bs-checkbox " style="text-align: center; vertical-align: middle; width: 36px; " data-field="id"><div class="th-inner "><input name="btSelectAll" type="checkbox"></div></th>*@
                                                <th class="text-center" data-field="Id"><div class="th-inner">序号</div></th>
                                                <th class="text-left" data-field="Name"><div class="th-inner">角色名</div></th>
                                                <th class="text-left" data-field="SystemName"><div class="th-inner">系统名称</div></th>
                                                <th class="text-left" data-field="Description"><div class="th-inner">描述</div></th>
                                                <th class="text-center" data-field="IsSystemRole"><div class="th-inner">是否系统角色</div></th>
                                                <th class="text-center" data-field="Active" data-formatter="strEnabledFormatter" data-align="center"><div class="th-inner">是否激活</div></th>
                                                <th data-field="Operator" data-align="center" class="text-center w250"><div class="th-inner">操作</div></th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @{
                                                int index = 0;
                                                foreach (var role in Model.UserRoleItems)
                                                {
                                                    <tr>
                                                        @*<td class="bs-checkbox ">
                                        <input data-index="@index" name="btSelectItem" class="btSelectItem" type="checkbox" value="@role.Id">
                                    </td>*@
                                                        <td class="text-center">@role.Id</td>
                                                        <td class="text-left">@role.Name</td>
                                                        <td class="text-left">@role.SystemName</td>
                                                        <td class="text-left">@role.Description</td>
                                                        <td class="text-center">

                                                            <div class="switch switch-primary">
                                                                <input id="IsSystemRoleRadioSwitch_@role.Id" type="radio" name="IsSystemRoleRadioSwitch_@role.Id" checked="@role.IsSystemRole">
                                                                <label for="IsSystemRoleRadioSwitch_@role.Id" class="mbn" />
                                                            </div>
                                                        </td>
                                                        <td class="text-center">
                                                            <div class="switch switch-primary">
                                                                <input id="ActiveRadioSwitch_@role.Id" type="radio" name="ActiveRadioSwitch_@role.Id" checked="@role.Active">
                                                                <label for="ActiveRadioSwitch_@role.Id" class="mbn" />
                                                            </div>
                                                        </td>
                                                        <td class="text-center">
                                                            <a class="btn btn-sm btn-primary btn_addgroup" data-id="@role.Id" href="@Url.Action("Edit",new { id=role.Id })"  title="编辑"><i class="glyphicon glyphicon-pencil mr5"></i> 编辑</a>
                                                            @*<a class="btn btn-sm btn-danger btn_delete" data-id="@role.Id" href="javascript:;" title="删除"><i class="glyphicon glyphicon-remove mr5"></i> 删除</a>*@
                                                            <a class="btn btn-sm btn-warning btn_setauthorization" data-id="@role.Id" href="@Url.Action("List","Permission",new { roleId=role.Id })"  title="授权"><i class="glyphicon glyphicon-cog mr5"></i> 授权</a>
                                                        </td>

                                                    </tr>
                                                    index++;
                                                }

                                            }
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                            @{
                                var pager = Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber");
                            }

                            @if (!pager.IsEmpty())
                            {
                                <div class="fixed-table-pagination" style="display: block;">
                                    @Html.Raw(pager.ToString())
                                </div>
                            }

                        </div>

                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
        </div>


    </section>

    <!-- End: Content -->
</section>


@{ await Html.RenderPartialAsync("_ModalForm", new ViewDataDictionary(ViewData) { { "formId", "UserRoleForm" }, { "showSave", "true" } }); }
@{ await Html.RenderPartialAsync("_SetAuthorization"); }



@section CurPageScripts
{

<script type="text/javascript">

        jQuery(document).ready(function () {

            "use strict";

            // Init Theme Core
            Core.init();

            // Init Demo JS
            Demo.init();

			//权限提示
			if ($(this).getUrlQueryString("Authorize") == "noAuthorize") {
				$('#alert-demo-2').fadeToggle();
				setTimeout(function () {
					$('#alert-demo-2').fadeToggle();
				}, 3000);
			}

			//全选
			$("input[name='btSelectAll']").click(function () {
				var selectStatus = $(this).is(':checked')
				if (selectStatus) {
					$("input[name='btSelectItem']").each(function (i, n) {
						n.checked = true;
					});
				} else {
					$("input[name='btSelectItem']").each(function (i, n) {
						n.checked = false;
					});
				}
			});

			//高级搜索
			$("#panel0 #AdvancedSearch").click(function () {
				var ico = $(this).find(".fa");
				if (ico.hasClass('fa-angle-double-right'))
					ico.removeClass("fa-angle-double-right").addClass("fa-angle-double-down");
				else
					ico.removeClass("fa-angle-double-down").addClass("fa-angle-double-right");
				$("#panel0").find(".panel-body").toggleClass("hidden fadeIn");
			});

            var $formSection = $(".formSection");
            //添加
            $("#btn_add", $formSection).click(function () {
                //location.href = "@Url.Action("Create")";
                window.open("@Url.Action("Create")","_blank");
            });

            //刷新
            $("#btn_refresh", $formSection).click(function ()
            {
                location.href = "@Url.Action("List")";
            });

            //删除
            $(".btn_delete", $formSection).click(function ()
            {

                WinMsg.confirm({ message: "确认要删除选择的数据吗？" }).on(function (e) {
                    if (!e) {
                        return;
                    }
                    location.href = "@Url.Action("Delete")?ids=" + $(this).attr("data-id");
                });
            });

            //授予权限
            $(".btn_setauthorization", $formSection).click(function () {
                var actionUrl = "/Security/SetAuthorization";
                var param = { id: $(this).attr("data-id") };
                ShowModal_Authorize(actionUrl, param, "授予角色权限");
            });

            //模态框中“权限授权”保存
            var $modal = $("#authorizeModal");
            $("#authorizebtnSave", $modal).click(function () {
                var actionUrl = "/Security/SetAuthorization";
                SaveModal_Authorize(actionUrl);
            });

        });
</script>
}
